package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.MsEmergencyVo;
import org.dromara.nursing.domain.bo.MsEmergencyBo;
import org.dromara.nursing.service.IMsEmergencyService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 紧急需求
 *
 * @author Lion Li
 * @date 2025-04-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/emergency")
public class MsEmergencyController extends BaseController {

    private final IMsEmergencyService msEmergencyService;

    /**
     * 查询紧急需求列表
     */
    // @SaCheckPermission("nursing:emergency:list")
    @GetMapping("/list")
    public TableDataInfo<MsEmergencyVo> list(MsEmergencyBo bo, PageQuery pageQuery) {
        return msEmergencyService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出紧急需求列表
     */
    // @SaCheckPermission("nursing:emergency:export")
    @Log(title = "紧急需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MsEmergencyBo bo, HttpServletResponse response) {
        List<MsEmergencyVo> list = msEmergencyService.queryList(bo);
        ExcelUtil.exportExcel(list, "紧急需求", MsEmergencyVo.class, response);
    }

    /**
     * 获取紧急需求详细信息
     *
     * @param id 主键
     */
    // @SaCheckPermission("nursing:emergency:query")
    @GetMapping("/{id}")
    public R<MsEmergencyVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(msEmergencyService.queryById(id));
    }

    /**
     * 新增紧急需求
     */
    // @SaCheckPermission("nursing:emergency:add")
    @Log(title = "紧急需求", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MsEmergencyBo bo) {
        return toAjax(msEmergencyService.insertByBo(bo));
    }

    /**
     * 修改紧急需求
     */
    // @SaCheckPermission("nursing:emergency:edit")
    @Log(title = "紧急需求", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MsEmergencyBo bo) {
        return toAjax(msEmergencyService.updateByBo(bo));
    }

    /**
     * 删除紧急需求
     *
     * @param ids 主键串
     */
    // @SaCheckPermission("nursing:emergency:remove")
    @Log(title = "紧急需求", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(msEmergencyService.deleteWithValidByIds(List.of(ids), true));
    }
}
